//package com.yunyv.iotudpserve.TCP.listener;
//
//import cn.dev33.satoken.annotation.SaIgnore;
//import com.yunyv.iotudpserve.common.Request;
//import io.swagger.annotations.Api;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.net.Socket;
//
///********************************************************************************
// ** author： zhangtianhe
// ** date：2024年06月06日 20:06
// ** description&desc：
// *********************************************************************************/
//@Slf4j
//@RestController
//@SaIgnore
//@RequestMapping("/tcp")
//@Api(tags = "发送TCp数据")
//public class TcpClient {
////    @SaIgnore
////    @PostMapping("/send")
////    public void send(@RequestBody @Validated Request<String> request) {
////        String serverIp = "127.0.0.1"; // 服务器IP地址
////        int serverPort = 62011;        // 服务器端口号
////        String message = request.getData(); // 要发送的消息
////
////        try (Socket socket = new Socket(serverIp, serverPort);
////             OutputStream outputStream = socket.getOutputStream()) {
////            // 将消息转换为字节数组
////            byte[] bytesToSend = message.getBytes();
////
////            // 发送消息
////            outputStream.write(bytesToSend);
////// 关闭Socket
//////            socket.close();
////            System.out.println("TCP message==========="+message);
////        } catch (IOException e) {
////            e.printStackTrace();
////        }
////    }
//
//    @SaIgnore
//    @PostMapping("/send")
//    public void send(@RequestBody @Validated Request<String> request) {
//        String serverIp = "127.0.0.1"; // 服务器IP地址
//        int serverPort = 62011;        // 服务器端口号
//        String message = request.getData(); // 要发送的消息
//        try {
//            Socket socket = new Socket(serverIp, serverPort);
//            socket.setSoTimeout(5000);
//
//            OutputStream outputStream = socket.getOutputStream();
//            InputStream inputStream = socket.getInputStream();
//
//            while (true) {
//                // 发送请求
//                String re = "Hello, Server!";
//                byte[] requestData = re.getBytes();
//                outputStream.write(requestData);
//                outputStream.flush();
//
//                // 接收响应
//                byte[] responseData = new byte[1024];
//                int bytesRead = inputStream.read(responseData);
//                if (bytesRead > 0) {
//                    String response = new String(responseData, 0, bytesRead);
//                    System.out.println("Server response: " + response);
//                }
//
//                // 休眠一段时间
//                Thread.sleep(1000);
//            }
//
//            // 关闭连接
//            // socket.close();
//        } catch (IOException | InterruptedException e) {
//            e.printStackTrace();
//        }
//    }
//}
